package com.toune.movie.mvp.model;

import android.util.Log;
import com.toune.movie.mvp.contract.PlayVideoContract;
import com.toune.movie.mvp.presenter.PlayVideoPresenter;
import com.toune.movie.vo.VarietyDetailVo;
import com.vondear.rxtool.RxThreadPoolTool;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

/**
 * Created by Administrator on 2018/5/15.
 */

public class PlayVideoModel implements PlayVideoContract.Model {
    PlayVideoPresenter playVideoPresenter;

    public PlayVideoModel(PlayVideoPresenter playVideoPresenter) {
        this.playVideoPresenter = playVideoPresenter;
    }

    @Override
    public void getPlayUrl(final String url) {
        new RxThreadPoolTool(RxThreadPoolTool.Type.CachedThread, 1).execute(new Runnable() {
            @Override
            public void run() {
                paseHtml(url);
            }
        });
    }


    private void paseHtml(String url) {
        try {
            VarietyDetailVo varietyDetailVo = new VarietyDetailVo();
            //还是一样先从一个URL加载一个Document对象。
            Document doc = Jsoup.connect(url).get();
            Elements playerDiv = doc.getElementsByTag("iframe");
            playVideoPresenter.setPlayUrl(playerDiv.get(0).attr("src"));
        } catch (Exception e) {
            Log.i("mytag", e.toString());
        }
    }
}
